<!-- Loads initialization file with a couple of variables -->

<%@ include file="../../inc/init.jsp" %>

<html>
	<head>
		<title>
			Graduate Admission System | University of California - San Diego | 
			Applications Page
		</title>
		<link type="text/css" rel="stylesheet" href="<%= BASE %>css/main.css">
	</head>
	<body>
		<div class="header-top"></div>
		<div class="header">
			<a href="<%= BASE %>admin/index.jsp"><img src="<%= BASE %>img/logo.png"></a>
		</div>
		<div class="content">
		
		<table>
		<tr>
		<%
			/** Decide whether to show back buttom and if yes, which one **/
		
			if(request.getParameter("display") != null)
			{
				if(request.getParameter("display").equals("discipline"))
				{
					out.print("<td><a href=\"" + BASE + "admin/applications/disciplineAnalytics.jsp\">" +
							  "<img src=\"" + BASE + "img/back.png\"></a>&nbsp;</td>");	
				}	
				else if(request.getParameter("display").equals("specialization"))
				{
					out.print("<td><a href=\"" + BASE + "admin/applications/specializationAnalytics.jsp\">" +
						  	  "<img src=\"" + BASE + "img/back.png\"></a>&nbsp;</td>");	
				}
			}
		%>
			<td><a href="<%= BASE %>admin/index.jsp">
			<img src="<%= BASE %>img/home.png"></a>&nbsp;&nbsp;
			</td>
			<td><span style="color: #515151;">You are logged in as: <b><%= request.getRemoteUser() %></b></span>&nbsp;</td>
			<td><a href="<%= BASE %>logout.jsp?page=admin">
				<img src="<%= BASE %>img/logout.png"></a>
			</td>
		</tr>
		</table><br>
		
		<%
			/** Get the parameter display to dispatch **/
			
			String parDisplay = request.getParameter("display");
		
			ArrayList<HashMap<String, String>> al = new ArrayList<HashMap<String, String>>();
			HashMap<String, String> hm = new HashMap<String, String>();
				
			if(parDisplay == null)
			{				
				/** Get overview of applications and show them **/
				
				al = Applications.getOverview();
				
				if(al.size() == 0)
				{
					out.print("There are no applications up to now.");
				}
				else
				{
				
				out.print("<table class=\"border\"><tr><th>Id</th><th>Name</th><th>First Name</th></tr>");
				
				for(int i = 0; i < al.size(); i++)
				{
					hm = al.get(i);
					
					if(i%2 == 0)
					{
						out.print("<tr class=\"evenHover\">");
					}
					else
					{
						out.print("<tr class=\"oddHover\">");
					}
					
					out.print("<td>" + hm.get("id") + "</td><td>" + hm.get("name") + 
							  "</td><td>" + hm.get("first_name")  + "</td></tr>");
				}
					
				out.print("</table>");
				
				}
									
			}
			else if(parDisplay.equals("discipline"))
			{
				int parDisciplineId = Integer.parseInt(request.getParameter("id"));
				
				/** Get applicant for specific discipline and show them **/
				
				al = Applications.getDisciplinesUsers(parDisciplineId);
				
				out.print("<table class=\"border\"><tr><th>Id</th><th>Name</th><th>First Name</th></tr>");
				
				for(int i = 0; i < al.size(); i++)
				{
					hm = al.get(i);
					
					if(i%2 == 0)
					{
						out.print("<tr class=\"evenHover\">");
					}
					else
					{
						out.print("<tr class=\"oddHover\">");
					}
					
					out.print("<td>" + hm.get("id") + "</td><td>" + hm.get("name") +
							  "</td><td>" + hm.get("first_name")  + "</td></tr>");
				}
				
				out.print("</td></tr></table>");
				
			}
			else if(parDisplay.equals("specialization"))
			{
				int parSpecializationId = Integer.parseInt(request.getParameter("id"));
					
				/** Get applicant for specific specialization and display them **/
				
				al = Applications.getSpecializationsUsers(parSpecializationId);
				
				out.print("<table class=\"border\"><tr><th>Id</th><th>Name</th><th>First Name</th></tr>");
					
				for(int i = 0; i < al.size(); i++)
				{
					hm = al.get(i);
						
					if(i%2 == 0)
					{
						out.print("<tr class=\"evenHover\">");
					}
					else
					{
						out.print("<tr class=\"oddHover\">");
					}
					out.print("<td>" + hm.get("id") + "</td><td>" + hm.get("name") +
							  "</td><td>" + hm.get("first_name")  + "</td></tr>");
				}
					
				out.print("</table>");		
			}
		%>
		</div>
	</body>
</html>